/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.izu.mytruco.deck;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Random;

/**
 *
 * @author Ademar
 */
public class Deck {

    public static final Integer FIRST_VALUE = 4;
    public static final Integer LAST_VALUE = 13;

    protected Deque<Card> cards;

    public Deck(){
        init();
    }

    protected void init() {
        cards = new ArrayDeque(40);
        for (Suit suit : Suit.getSuits()) {
            for (int i = FIRST_VALUE; i < LAST_VALUE; i++) {
                cards.push(createCard(suit, i));
            }
        }
    }

    protected Card createCard(Suit suit, int value) {
        String name = String.valueOf(value);
        switch (value) {
            case 8:
                name = "Queen";
                break;
            case 9:
                name = "Jack";
                break;
            case 10:
                name = "King";
                break;
            case 11:
                name = "Ace";
                break;
            case 12:
                name = "2";
                break;
            case 13:
                name = "3";
                break;
        }
        return new Card(name, suit, value);
    }

    public Deque<Card> getCards() {
        return cards;
    }

    public void sort(Long seed) {
        Random  random = new Random(seed);
        Deque<Card> sortedDeck = new ArrayDeque<Card>();
        while (sortedDeck.size() < cards.size()) {
            Card card = (Card)cards.toArray()[random.nextInt(cards.size())];
            if (!sortedDeck.contains(card)) {
                sortedDeck.add(card);
            }
        }
        this.cards = sortedDeck;
    }

    public static void main(String[]args){
        Deck d = new Deck();
        d.sort(System.currentTimeMillis());
        for (Card card : d.getCards()) {
            System.out.println(card);
        }
    }
}
